<?php
error_reporting(0);
ini_set('include_path', '.:/home/bpedro/pear/lib/php:/usr/local/php5/lib/php');

require_once 'Delicioso.php';

$username = 'deliblog';
$password = 'deliblog';
$url = 'http://remix.wevel.com/delicioso/';
$dlc =& new Delicioso($username, $password, $url);

$title = null;
$body = null;
$id = null;

if (!empty($_GET['id'])) {
	$posts = $dlc->getPost($_GET['id']);
	if (!empty($posts)) {
		$title = $posts[0]['description'];
		$body = stripslashes(preg_replace('/<br\s*?\/?>/i', '', $posts[0]['extended']));
		$id = $_GET['id'];
	}
}


if (!empty($_POST['title']) && !empty($_POST['body'])) {
	if (!empty($_POST['id'])) {
		$res = $dlc->post($_POST['title'], $_POST['body'], array(), $_POST['id']);
	} else {
    	$res = $dlc->post($_POST['title'], $_POST['body']);
	}
}
?>
<html>
<body>
<?php if ($res) { ?>
<strong>Your post has been saved.</strong>
<?php } ?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php if (!empty($id)) { ?>
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<?php } ?>
<p>
<b>Title:</b><br />
<input type="text" name="title" size="50" value="<?php echo $title; ?>"/>
</p>

<p>
<b>Body:</b><br />
<textarea name="body" cols="50" rows="20"><?php	echo $body; ?></textarea>
</p>

<p>
<input type="submit" value="Post" />
</p>
</form>
</body>
</html>
